home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 3
/
Cream of the Crop 3.iso
/
clipper
/
ks94an.zip
/
NEAREST.HDR
< prev
next >
Wrap
Text File
|
1994-04-25
|
4KB
|
132 lines
/******************************************************************************
The Klipper Library, for CA-Clipper 5.x
Copyright (c), 1994, Wallace Information Systems Engineering
FUNCTION:
_Nearest( nNum1, nNum2 nTarget, nRange )
PARAMETERS:
nNum1 : first number to test against nTarget
nNum2 : second number to test against nTarget
nTarget : nTarget (the number that nNum1 and nNum2 are tested against)
nRange : 0 = return nearest without EXceeding nTarget
1 = Return nearest (DEFAULT)
2 = Return nearest without PREceeding nTarget
SHORT:
Determine which of two values is closest to target value (with rules).
DESCRIPTION:
_Nearest() is a fairly complex function that compares nNum1 and nNum2 against
nTarget and returns:
1 - nNum1 is nearer to nTarget than nNum2 WITHIN the given rules
2 - nNum2 is nearer to nTarget than nNum1 WITHIN the given rules
0 - Neither number is closer to nTarget WITHIN the given rules because:
EITHER : nNum1 and nNum2 BOTH exceed nTarget and nRange = LOW
OR : nNum1 and nNum2 BOTH preceede nTarget and nRange = HIGH
OR : nNum1 = nNum2
OR : (lower_num+n) = (higher_num-n) and RANGE = CLOSEST
Examples of conditions returning a value of 0:
************************ EX 1
nNum1 = 6
nTarget = 7
nNum2 = 8
(6+1) = 7 = (8-1)
************************ EX 2
nNum1 = 4
nTarget = 8
nNum2 = 12
(4+4) = 8 = (12-4)
************************ EX 3
nNum1 = 12
nTarget = 8
nNum2 = 4
(12-4) = 8 = (4+4)
In other words, Range = CLOSEST, but both numbers are equidistant from
nTarget on opposite sides. More examples follow.
NOTE:
EXAMPLE:
#define CLOSEST 0
#define LOW 1
#define HIGH 2
? 'CLOSEST EXAMPLES'
? '---------------------------------------------------------------'
? _Nearest(3,4,5) // 2 - Range Not specified so default is
? _Nearest(4,3,5) // 1 - CLOSEST
? _Nearest(3,4,5,CLOSEST) // 2 - These will be the same as above
? _Nearest(4,3,5,CLOSEST) // 1 - because of default to CLOSEST
? _Nearest(4,4,5,CLOSEST) // 0 - nNum1 = nNum2 : neither are nearer
? _Nearest(5,5,5,CLOSEST) // 0 - ditto
? 'HIGH EXAMPLES'
? '---------------------------------------------------------------'
? _Nearest(9,12,10,HIGH) // 2 - because 9 is lower than nTarget
? _Nearest(9,1000,10,HIGH) // 2 - ditto above
? _Nearest(8,9,10,HIGH) // 0 - Both are below nTarget
? 'LOW EXAMPLES'
? '---------------------------------------------------------------'
? _Nearest(7,5,10,LOW) // 1
? _Nearest(7,11,10,LOW) // 1 - because 11 exceeds nTarget
? _Nearest(7,7,10,LOW) // 0 - Both are equal
? _Nearest(6,7,10,LOW) // 2
? _Nearest(17,18,10,LOW) // 0 - Both exceed nTarget
? _Nearest(17,17,10,LOW) // 0 - Both equal/exceed nTarget
? 'EQUALITY EXAMPLES - not equal to each other but from nTarget'
? '---------------------------------------------------------------'
? _Nearest(5,7,6,CLOSEST) // All these return 0
? _Nearest(4,6,5,CLOSEST) //
? _Nearest(13,7,10,CLOSEST) //
? _Nearest(7,13,10,CLOSEST) //
? 'MORE EXAMPLES'
? '---------------------------------------------------------------'
? _Nearest(4,4,5) // 0 neither is nearer than the other
? _Nearest(4.1,3,5) // 1
? _Nearest(3,6,5) // 2
? _Nearest(3,6,5,LOW) // 1 (nNum2 exceeds nTarget)
? _Nearest(6,3,5,LOW) // 2 (nNum1 exceeds nTarget)
Note that _Nearest() will also accept dates in place of nNum1, nNum2
and nTarget:
t = _Nearest(ctod('01/21/93), ctod('01/26/93'), ctod('01/25/93'), LOW)
Result: t = 1 // because 01/26/93 exceeds target date and Range = LOW
******************************************************************************/